package Twice.day05;


import java.util.Arrays;

/**
 * @Author: lya
 * @Description: 本类的作用描述:学生实体类
 * @CreateDate: 2019/8/27
 * @Version: 1.0
 */
public class Student {
    private Integer id;
    private String sno;
    private String sname;
    private Integer age;
    private String[] hobbies;

    private Clazz clazz;

    //---------------构造-----------
    public Student() {
        System.out.println("空参构造被调用了!");
    }
    /**
     * 两参构造
     */
//    public Student(Integer sid,String name){
//        System.out.println("带参构造被调用了!");
//        System.out.println("id = " + id);
//        System.out.println("sname = " + sname);

        //可以出现在构造方法中可以使用非静态成员[非静态属性]
        //JVM加载类进内存的时候
        //优先加载的所有的静态的成员[分配空间以及初始化]
        //当创建对象的时候 Student st = new Student(19,"haha");
        //会优先给所有的非静态的成员分配空间以及初始化
        //然后才是去调用构造方法["肉眼能看到的"]
        //id = sid;
        //sname = name;

//    }

    public Student(Integer id,String sname){
        //this();//去调用本类中已经存在的空参构造
        System.out.println("两参构造被调用了.....");
        this.id = id;
        this.sname = sname;
    }

    /**
     * 三参构造
     * @param id
     * @param sno
     * @param sname
     */

    public Student (Integer id ,String sno,String sname){
        this(id,sname);//调用当前的两参构造
        System.out.println("三参构造...");
        this.id = id;
        this.sname = sname;
        this.sno = sno;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getSno() {
        return sno;
    }

    public void setSno(String sno) {
        this.sno = sno;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        if ("cnm".equals(sname)){
            this.sname = "***";
            return;
        }

        this.sname = sname;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String[] getHobbies() {
        return hobbies;
    }

    public void setHobbies(String[] hobbies) {
        this.hobbies = hobbies;
    }

    public Clazz getClazz() {
        return clazz;
    }

    public void setClazz(Clazz clazz) {
        this.clazz = clazz;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Student{");
        sb.append("id=").append(id);
        sb.append(", sno='").append(sno).append('\'');
        sb.append(", sname='").append(sname).append('\'');
        sb.append(", age=").append(age);
        sb.append(", hobbies=").append(Arrays.toString(hobbies));
        sb.append(", clazz=").append(clazz);
        sb.append('}');
        return sb.toString();
    }
}
